package top.yxqz.resp;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Mr.余
 * @date 2022/11/18
 * @package top.yxqz.resp
 * 1. PrintWriter 和 ServletOutputStream不可以同时使用
 */
@WebServlet("/demo1")
public class RespDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        字符流输出
        PrintWriter writer = response.getWriter();
        writer.println("hello world呵呵哈哈哈");

//        ServletOutputStream outputStream = response.getOutputStream();
//        outputStream.println(999);

//        关闭流  （我们也可以不用主动关这个流，tomcat中的servlet会自动帮我们关）
        writer.close();

    }
}
